#pragma once

#include "types.h"

OPEN_JLIB_NS


template<typename Closeable>
struct AutoClose {

  typedef Closeable device_t;

  inline explicit AutoClose (device_t& device) noexcept : _device(device) {
    _device.open();
  }

  inline ~AutoClose () noexcept {
    _device.close();
  }

  AutoClose (const device_t&) = delete;
  AutoClose& operator= (const AutoClose&) = delete;

private:
  device_t& _device;
};


CLOSE_JLIB_NS